package lesson.tcs;

import lesson.base.BaseServlet;
import lesson.permission.Role;
import lesson.user.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/tcs/*")
@Role(User.ROLE_ADMIN)
public class TeacherClassSubjectServlet extends BaseServlet {

    private TeacherClassSubjectService service = new TeacherClassSubjectService();


    /**
     * 添加教师教任的班级学科
     * @param tcs
     * @throws ServletException
     * @throws IOException
     */
    public void add(TeacherClassSubject tcs) throws ServletException, IOException {

        String result = service.add(tcs);

        writeJSON(result == null, result);

    }

    /**
     * 删除某一条班级学科
     * @param id
     * @throws ServletException
     * @throws IOException
     */
    public void del(Integer id) throws ServletException, IOException {
        String result = service.del(id);
        if (result == null) {
            writeJSON(true);
        } else {
            writeJSON(false, result);
        }
    }

    /**
     * 列出某个老师教任的班级学科
     * @param teacherId
     */
    public void list(Integer teacherId) throws ServletException, IOException {

        List<TeacherClassSubject> list = service.list(teacherId);

        writeJSON(true, null, list);

    }

}
